let MS = require('./ms')
const request = require('./request')
const {
    isObject,
    isString,
    isNumber,
    isUndefined,
    isBoolean,
    isArray
} = require('./dataType')

const synopsis = class synopsis {
    constructor() {}

    get() {
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.APP_SYNOPSIS.GET.url,
                MS._config.parameters.APP_SYNOPSIS.GET.method, {}).then(res => {
                    if(res.success) {
                        resolve(res.data)
                    } else {
                        reject(res.message)
                    }
            }).catch(err => {
                reject(err)
            })
        })
    }

    create() {
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.APP_SYNOPSIS.CREATE.url,
                MS._config.parameters.APP_SYNOPSIS.CREATE.method, {}).then(res => {
                    if(res.success) {
                        resolve(res.data)
                    } else {
                        reject(res.message)
                    }
            }).catch(err => {
                reject(err)
            })
        })
    }

    update(options) {
        let params = {}
        if(!isUndefined(options) && isObject(options)) {
            if(!isUndefined(options.title) && isString(options.title)) {
                params.title = options.title;
            }
            if(!isUndefined(options.content) && isString(options.content)) {
                params.content = options.content;
            }
            if(!isUndefined(options.status) && isBoolean(options.status)) {
                params.status = options.status;
            }
        }
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.APP_SYNOPSIS.UPDATE.url,
                MS._config.parameters.APP_SYNOPSIS.UPDATE.method, params).then(res => {
                    if(res.success) {
                        resolve(res.data)
                    } else {
                        reject(res.message)
                    }
            }).catch(err => {
                reject(err)
            })
        })
    }
}

module.exports = synopsis